package jframe.listener;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import jframe.base.dao.DaoHibernateBase;
import jframe.cache.OscacheFactory;
import jframe.cache.SystemParamaterCache;
import jframe.common.Context;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.context.support.WebApplicationContextUtils;

/**
 * @描述:<p>初始化Context静态对象 </p>
 *
 * @作者: 叶平平(yepp)
 *
 * @时间: 2011-6-19 上午10:09:28
 */
public class ContextLoaderListener implements ServletContextListener  {
	private static final Log log = LogFactory.getLog(ContextLoaderListener.class);
	
	//启动加载
	public void contextInitialized(ServletContextEvent event) {
		
		//1.注入Context对象
		ServletContext context = event.getServletContext();
		log.info(context);
		Context.servletContext = context;
		Context.webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(context);
		
		//查询oscacheFactory
		OscacheFactory oscacheFactory = (OscacheFactory) Context.getSpringBean("oscacheFactory");
		
		//2.注入SystemParamaterCache对象
		SystemParamaterCache.oscacheFactory = oscacheFactory;
		SystemParamaterCache.daoHibernateBase = (DaoHibernateBase) Context.getSpringBean("daoHibernateBase");
		
		//3.缓存所有字典
		SystemParamaterCache.cacheAllDict();
		
		//4.缓存所有操作
		SystemParamaterCache.cacheAllOperator();
		
		
	}
	
	
	//销毁
	public void contextDestroyed(ServletContextEvent event) {
		// TODO Auto-generated method stub
		
	}

	

}
